package br.ufpe.cin.camid.core.lifecycle;

import java.util.List;
import java.util.TimerTask;

import br.ufpe.cin.camid.core.agents.Agent;

import com.google.inject.Inject;

@Agent
public class LeasingAgent extends TimerTask {

	@Inject
	private ObjectManagerFacade objectManager;
	
	public LeasingAgent() 
	{
		super();
	}

	@Override
	public void run() 
	{
		List<ManagedObjectLease> leases = objectManager.getManagedObjectLeases();
		for(ManagedObjectLease lease : leases)
		{
			if(lease.hasActivationExpired())
			{
				objectManager.remove(lease.getObjectId());
			}
		}
	}

}
